import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:fluro/fluro.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'utils/layout/layout.dart';

import 'package:provider/provider.dart';

import 'providers/page_provider.dart';
import 'routes/routes.dart';
import 'utils/g.dart';
import 'utils/custom/custom_theme.dart';
import 'utils/custom/custom_localizations.dart';

void main() {
  // 初始化路由
  Routes.configureRoutes(G.router); // 初始化后的路由，放到全局组件中


  runApp(
    // 使用 Provider
    MultiProvider(
      providers: [
        ChangeNotifierProvider(create: (_) => PageProvider()),
      ],
      child: MyApp(),
    ),
  );
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      debugShowCheckedModeBanner: false,
      navigatorKey: G.navigatorKey, // 声明全局 key，然后才能获取全局上下文
      // theme: ThemeData(
      //   primarySwatch: Colors.blue,
      // ),
      theme: CustomTheme.lightTheme, // 高亮主题
      darkTheme: CustomTheme.darkTheme, // 黑暗主题
      home: Layout(),
      builder: EasyLoading.init(),
      localizationsDelegates: [
        // 本地化的代理类
        CustomLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,  // Material 国际化
        GlobalCupertinoLocalizations.delegate, // Cupertino 国际化
        GlobalWidgetsLocalizations.delegate,   // Widgets 国际化
      ],
      supportedLocales: [
        const Locale('en', 'US'), // 美国英语
        const Locale('zh', 'CN'), // 中文简体
      ]
    );
  }
}
